package com.handinglian.ai.template.controller;

import com.apidoc.annotation.Api;
import com.handinglian.ai.common.dto.CommonPage;
import com.handinglian.ai.common.dto.ResultData;
import com.handinglian.ai.template.dto.CallTemplateDto;
import com.handinglian.ai.template.param.CallTemplateCreateParam;
import com.handinglian.ai.template.param.CallTemplateUpdateParam;
import com.handinglian.ai.template.service.CallTemplateService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api("通话模板")
@RestController
@Slf4j
@RequestMapping("/calltemplate")
public class CallTemplateController {
    @Autowired
    private CallTemplateService callTemplateService;
    
    /**
     * 创建通话模板
     */
    @PostMapping(value = "/create")
    public ResultData create(@RequestBody CallTemplateCreateParam createParam) {
        return ResultData.success(callTemplateService.create(createParam));
    }

    /**
     * 删除通话模板
     */
    @DeleteMapping(value = "/delete")
    public ResultData delete(Integer id) {
        return ResultData.success(callTemplateService.delete(id));
    }

    /**
     * 批量删除
     */
    @DeleteMapping(value = "/deleteBatch")
    public ResultData deleteBatch(String id) {
        return ResultData.success(callTemplateService.deleteBatch(id));
    }

    /**
     * 更新通话模板
     */
    @PutMapping(value = "/update")
    public ResultData update(@RequestBody CallTemplateUpdateParam updateParam) {
        return ResultData.success(callTemplateService.update(updateParam));
    }

    /**
     * 获取通话模板列表
     */
    @GetMapping(value = "/listPage")
    public ResultData<CommonPage<CallTemplateDto>> listPage(String nameOrContent,
                                                            String type,
                                                            String sortField,
                                                            String sortOrder,
                                                            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        return ResultData.success(callTemplateService.listPage(nameOrContent, type, sortField, sortOrder, pageNum, pageSize));
    }

    /**
     * 获取某类型通话模板
     */
    @GetMapping(value = "/list")
    public ResultData<CallTemplateDto> list(Integer type) {
        return ResultData.success(callTemplateService.list(type));
    }

    /**
     * 获取通话模板详情
     */
    @GetMapping(value = "/getDetail")
    public ResultData<CallTemplateDto> getDetail(Integer id) {
        return ResultData.success(callTemplateService.getDetail(id));
    }

    /**
     * 设置默认通话模板
     */
    @GetMapping(value = "/setDefault")
    public ResultData setDefault(Integer id) {
        return ResultData.success(callTemplateService.setDefault(id));
    }
}
